<?php 
/* SVN FILE: $Id$ */
/* Product Test cases generated on: 2009-11-10 10:58:13 : 1257818293*/
App::import('Model', 'Product');
class ProductTestCase extends CakeTestCase {
	var $Product = null;
	var $fixtures = array('app.product');

	function startTest() {
		$this->Product =& ClassRegistry::init('Product');
		$f = new ProductFixture;
		#debug($f->getRecords());
		foreach( $f->getRecords() as $key => $value ){
			$this->{$key} = $value;
		}
	}

	function testProductInstance() {
		$this->assertTrue(is_a($this->Product, 'Product'));
	}

	function testProductFind() {
		$this->Product->recursive = -1;
		$results = $this->Product->find('first');
		$this->assertTrue(!empty($results));

		$expected = array('Product' => array(
			'id'  => 1,
			'title'  => 'Lorem ipsum dolor sit amet',
			'description'  => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida,phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam,vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit,feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.',
			'image_url'  => 'http://hogehoge.com/foo.jpg',
			'price'  => '12345.6',
			'date_available'  => '2009-11-10 10:58:13'
		));
		$this->assertEqual($results, $expected);
	}
	function testProductUpdateBySaveField(){
		$this->Product->recursive=-1;
		$results = $this->Product->find('first');
		#debug($results);
		$results['Product']['price'] = 99.99;
		$this->Product->id = 1;
		$this->Product->saveField('price',99.99);
		#$this->Product->save($results); #は動作しなかった。まだcakePHPが理解できていないようだ
		$results=$this->Product->find('first');
		#debug($results);
		$expected = array('Product' => array(
			'id'  => 1,
			'title'  => 'Lorem ipsum dolor sit amet',
			'description'  => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida,phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam,vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit,feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.',
			'image_url'  => 'http://hogehoge.com/foo.jpg',
			'price'  => '99.99',
			'date_available'  => '2009-11-10 10:58:13'
		));
		$this->assertEqual($results, $expected);
	}
	function testProductDelete(){
		$results = $this->Product->find('first');
		$id = $results['Product']['id'];
		$this->Product->del($id);
		$count = $this->Product->find('count',array('conditions' => array('Product.id' => $id)));
		$this->assertEqual($count,0);
	}
	function testProductValidte(){
		$this->Product->recursive=-1;
		$results = $this->Product->find('first');
		$results['Product']['price'] = "0.0"; # 文字列として入力することに注意
		$this->Product->set($results);
		$result=$this->Product->validates();
		$errors = $this->Product->validationErrors;
		#debug($errors);
		$this->assertEqual($errors,array('price' => '0より大きい価格を設定してください'));
	}
	function testDynamicFixture(){
		$this->Product->recursive = -1;
		$results = $this->Product->find('first');
		$this->assertTrue(!empty($results));
		#debug($this->version_control_book);
		#debug($results);
		$this->assertEqual($results['Product'], $this->version_control_book);
		
		$results = $this->Product->find('first',array('conditions' => array('Product.id' => 2)));
		#debug($this->automation_book);
		#debug($results);
		$this->assertEqual($results['Product'], $this->automation_book);
	}
	function testSalabeItems(){
		$results = $this->Product->salable_items();
		foreach( $results as $result){
			#debug($result['Product']);
			$this->assertTrue($result['Product']['date_available'] <= date('Y-n-j'));
		}
	}
    
    function create(){
        return false;
    }

    function drop(){
        return false;
    }
}
?>